home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
menu.c
< prev
next >
Wrap
Text File
|
1992-04-17
|
15KB
|
644 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#if !defined(USEDUMP)
#include "maclib.h"
#include "termdef.h"
#include "tn3270funcs.h"
#include "globals.h"
#else
#pragma load "tn3270DumpFile"
#endif
#include "netevent.h"
#include "hostform.h"
#include "NCSAfuncs.h" /* must follow hostform.h */
#pragma segment 3270seg2
#define langMenu 234
#define kmapMenu 235
#define cfigMenu 236
#define appleMenu 256
#define fileMenu 257
#define editMenu 258
#define setMenu 259
#define fkeyMenu 260
#define netMenu 261
#define connMenu 262
extern char da_menu;
extern int MacBinary;
extern char showstg;
extern char mdm_open; /* modem port is open */
extern char serserverconn; /* connected to serial server */
char ftpavail;
void menu_upd(void)
{
short i, msize;
char fullscreen, checkflag, enableflag;
unsigned char itemname[256];
cnr *cp, *conncp;
cp = front_cp();
/* language menu */
msize = CountMItems(nlMenu);
for (i=1; i <= msize; i++) {
GetItem(nlMenu, i, itemname);
p2cstr(itemname);
checkflag = false;
if (cp != 0) checkflag = strcmp(itemname, cp->csnlname) == 0;
CheckItem(nlMenu, i, checkflag);
}
/* keyboard menu */
msize = CountMItems(kybdMenu);
for (i=1; i <= msize; i++) {
GetItem(kybdMenu, i, itemname);
p2cstr(itemname);
checkflag = false;
if (cp != 0) checkflag = strcmp(itemname, cp->cskybdname) == 0;
CheckItem(kybdMenu, i, checkflag);
}
/* file menu */
if (cp != 0) {
if (zoomstate(cp) == inZoomOut) {
SetItem(myMenus[1], 5, "\pZoom Out");
}
else {
SetItem(myMenus[1], 5, "\pZoom In");
}
CheckItem(myMenus[1], 10, cp->savepict != 0);
CheckItem(myMenus[1], 16, cp->kabort != 0);
}
else {
SetItem(myMenus[1], 5, "\pZoom In");
CheckItem(myMenus[1], 10, 0);
CheckItem(myMenus[1], 16, 0);
}
if (da_menu) {
DisableItem(myMenus[1], 1);
DisableItem(myMenus[2], 2);
DisableItem(myMenus[1], 3);
DisableItem(myMenus[1], 5);
DisableItem(myMenus[1], 7);
DisableItem(myMenus[1], 8);
DisableItem(myMenus[1], 10);
DisableItem(myMenus[1], 12);
DisableItem(myMenus[1], 13);
if (havesa) DisableItem(myMenus[1], 14);
DisableItem(myMenus[1], 15);
DisableItem(myMenus[1], 16);
DisableItem(myMenus[1], 17);
if (havesa) DisableItem(myMenus[1], 18);
CheckItem(myMenus[1], 19, 0);
}
else {
enableflag = 0;
for (i=0; i < MAXSESSIONS; i++) {
if (cplist[i] == 0) {
enableflag = 1;
break;
}
}
enable_menu_item(myMenus[1], 1, enableflag);
EnableItem(myMenus[1], 2);
EnableItem(myMenus[1], 12);
if (havesa) {
enable_menu_item(myMenus[1], 14,
(serserverconn == 0) && mdm_open);
enable_menu_item(myMenus[1], 18, serserverconn);
}
if (cp == 0) {
DisableItem(myMenus[1], 3);
DisableItem(myMenus[1], 5);
enable_menu_item(myMenus[1], 7, enableflag);
DisableItem(myMenus[1], 8);
DisableItem(myMenus[1], 10);
DisableItem(myMenus[1], 13);
DisableItem(myMenus[1], 15);
DisableItem(myMenus[1], 16);
DisableItem(myMenus[1], 17);
CheckItem(myMenus[1], 19, 0);
}
else {
EnableItem(myMenus[1], 3);
enable_menu_item(myMenus[1], 5, cp->zoomok && (cp->myWindow != 0));
if (cp->cs.autoconn == 0) {
enableflag = true;
}
enable_menu_item(myMenus[1], 7, enableflag);
EnableItem(myMenus[1], 8);
enable_menu_item(myMenus[1], 10, cp->PictPtr != 0);
enable_menu_item(myMenus[1], 13, cp->myWindow != 0);
EnableItem(myMenus[1], 15);
enable_menu_item(myMenus[1], 16, cp->vmxbgn);
enable_menu_item(myMenus[1], 17,
cp->xdlg && (cp->xdlgptr != FrontWindow()));
CheckItem(myMenus[1], 19, done);
}
}
/* Edit menu */
if (da_menu) {
EnableItem(myMenus[2], 1);
EnableItem(myMenus[2], 3);
EnableItem(myMenus[2], 4);
EnableItem(myMenus[2], 5);
EnableItem(myMenus[2], 6);
DisableItem(myMenus[2], 7);
DisableItem(myMenus[2], 8);
}
else {
DisableItem(myMenus[2], 1);
if (cp == 0) {
DisableItem(myMenus[2], 3); /* Cut */
DisableItem(myMenus[2], 4); /* Copy */
DisableItem(myMenus[2], 5); /* Paste */
DisableItem(myMenus[2], 6); /* Clear */
DisableItem(myMenus[2], 7); /* Copy Table */
DisableItem(myMenus[2], 8); /* Copy Text */
}
else {
if (cp->textsel) checksel(cp);
fullscreen = cp->connstate > 4;
enable_menu_item(myMenus[2], 3, cp->textsel && fullscreen); /* Cut */
enable_menu_item(myMenus[2], 4, cp->textsel); /* Copy */
enable_menu_item(myMenus[2], 5, pasteok); /* Paste */
enable_menu_item(myMenus[2], 6, cp->textsel && fullscreen); /* Clear */
enable_menu_item(myMenus[2], 7, cp->textsel); /* Copy Table */
enable_menu_item(myMenus[2], 8, cp->textsel); /* Copy Text */
}
}
/* Session menu */
enable_menu_item(myMenus[3], 4, colormac && (!cp->cs.nocolor));
enable_menu_item(myMenus[3], 6, (rowmax9 > 24) || (colmax9 > 80));
msize = CountMItems(kybdMenu);
enable_menu_item(myMenus[3], 8, msize > 1);
msize = CountMItems(nlMenu);
enable_menu_item(myMenus[3], 9, msize > 1);
/* Network menu */
if (havetcp) {
enable_menu_item(myMenus[5], 2, cp != 0);
CheckItem(myMenus[5], 3, ftpavail != 0);
CheckItem(myMenus[5], 4, MacBinary != 0);
enableflag = false;
if (cp != 0) {
enableflag = tcp_session(cp);
}
for (i = 6; i < 12; i++) {
enable_menu_item(myMenus[5], i, enableflag);
}
}
/* Connections menu */
for (i=1; i <= MAXSESSIONS; i++) {
conncp = menu_cplist[i];
if (conncp == 0) break;
CheckItem(myMenus[6], i, cp == conncp);
}
}
void docommand(long mResult, char append)
{
register short theItem, theMenu, i;
register unsigned char name[40];
WindowRecord * fw;
static unsigned char brkstr[] = {255, 243};
static unsigned char ipstr[] = {255, 244};
static unsigned char aostr[] = {255, 245};
static unsigned char aytstr[] = {255, 246};
static unsigned char ecstr[] = {255, 247};
static unsigned char elstr[] = {255, 248};
unsigned char itemname[256];
unsigned char **temph;
cnr *cp, *cptemp;
char cancelflag;
theMenu = mResult >> 16;
theItem = mResult & 0xff;
cp = front_cp();
switch(theMenu) {
case langMenu:
GetItem(nlMenu, theItem, itemname);
p2cstr(itemname);
if (theItem > 1) {
c2pstr(itemname);
temph = GetNamedResource('GFNL', itemname);
p2cstr(itemname);
if (temph != 0L) {
strcpy(cp->csnlname, itemname);
if (GetHandleSize(temph) == 1) {
cp->nl_handle = 0;
newstdfont(**temph, cp);
cp->plainala = 0;
}
else if (GetHandleSize(temph) == 3) {
cp->nl_handle = 0;
newstdfont(**temph, cp);
cp->plainala = ((*temph)[1] & 0x80) == 0x80;
}
else {
cp->nl_handle = temph;
defxtab(cp->nl_handle, cp->nltab);
newstdfont(NORMALFONT, cp);
cp->plainala = 0;
}
}
}
else {
strcpy(cp->csnlname, itemname);
cp->nl_handle = 0;
newstdfont(NORMALFONT, cp);
cp->plainala = 0;
}
if (cp->myWindow != 0) invldscr(cp);
break;
case kmapMenu:
GetItem(kybdMenu, theItem, itemname);
temph = GetNamedResource('GFKB', itemname);
p2cstr(itemname);
if (temph != 0L) {
cp->kb_handle = temph;
strcpy(cp->cskybdname, itemname);
}
break;
case cfigMenu:
switch(theItem) {
case 1:
hostcfdlg();
break;
case 2:
cf_fmtdlg();
break;
case 3:
cf_featdlg();
break;
case 4:
specdlg();
break;
default:
break;
}
break;
case appleMenu:
if (theItem == 2) break;
if (theItem == 1) {
aboutdlg();
if ((cp == 0) && showstg) {
stginfo(cp);
showstg = 0;
}
break;
}
GetItem(myMenus[0], theItem, name);
exportscrap(0);
OpenDeskAcc(name);
importscrap();
break;
case fileMenu:
switch (theItem) {
case 1: newlogin(0, 0, 0, 0, 0);
break;
case 3: if (!(cp->serflg && (cp->connstate <= 1))) {
closeresponse(closeUser, cp);
}
if (cp->serflg) serlgout(0, cp);
else if (cp->tcpflg) tcplgout(0, cp);
else salgout(0, cp);
break;
case 5: dozoom(cp->myWindow, zoomstate(cp));
break;
case 7: read_settings(0, cp);
break;
case 8: write_settings(cp);
break;
case 10:
cp->savepict ^= 1;
break;
case 12:
pgsetup();
break;
case 13:
prscreen(cp);
break;
case 14:
if (havesa) sersendinit(1);
break;
case 15:
crsetdlg(cp);
break;
case 16:
cp->kabort ^= 1;
break;
case 17:
if (cp->xdlg) SelectWindow(cp->xdlgptr);
break;
case 18:
if (havesa) sersrvlgout(1);
break;
case 19:
if (!da_menu) {
cancelflag = 0;
for (i=0; i < MAXSESSIONS; i++) {
cptemp = cplist[i];
if (cptemp != 0) {
cancelflag = (wants_to_quit(cptemp) == 0);
if (cancelflag) break;
}
}
if (!cancelflag) {
done ^= 1;
}
break;
}
else {
fw = (WindowRecord *)FrontWindow();
i = fw->windowKind;
if (i<0)CloseDeskAcc(i);
}
default: break;
}
break;
case editMenu:
if (da_menu) {
SystemEdit(theItem-1);
}
else {
switch(theItem) {
case 3: scrapcut(append, cp);
break;
case 4: scrapcopy(append, cp);
break;
case 5: scrappaste(cp);
break;
case 6: scrapclear(cp);
break;
case 7: scrapcopytable(append, cp);
break;
case 8: scrapcopytext(append, cp);
break;
default:
break;
}
}
break;
case setMenu:
switch (theItem) {
case 1: featdlg(cp);
break;
case 2: clickdlg(cp);
break;
case 3: attrdlg(cp);
break;
case 4: colordlg(cp);
if (cp->myWindow != 0) {
invldscr(cp);
cp->cs.stat_time += 8; /* force time to be re-drawn */
newstat(cp);
newinvbw(cp);
}
break;
case 5: psdlg(cp);
break;
case 6: fmtdlg(cp);
break;
case 7: miscdlg(cp);
break;
default: break;
}
break;
case fkeyMenu:
clickattn(theItem, cp);
break;
case netMenu:
switch (theItem) {
case 1: promptip(1); /* r/o network configuration */
break;
case 2: tcpinfo(cp); /* network status info. */
break;
case 3: ftpavail = !ftpavail; /* FTP Enable */
Sftpmode(ftpavail);
break;
case 4: MacBinary = !MacBinary; /* MacBinary mode */
break;
case 5: show_writeinfo(cp); /* debugging info */
break;
case 6: tcpwrite(brkstr, 2, cp); /* Break */
break;
case 7: tcpwrite(ipstr, 2, cp); /* Interrupt Process */
break;
case 8: tcpwrite(aostr, 2, cp); /* Abort Output */
break;
case 9: tcpwrite(aytstr, 2, cp); /* Are You There? */
break;
case 10: tcpwrite(ecstr, 2, cp); /* Erase Character */
break;
case 11: tcpwrite(elstr, 2, cp); /* Erase Line */
break;
default: break;
}
break;
case connMenu:
cptemp = menu_cplist[theItem];
if (cptemp != 0) {
if (cptemp->myWindow == 0) {
conndlg(cptemp);
}
else {
SelectWindow(cptemp->myWindow);
}
}
break;
default:
break;
}
HiliteMenu(0);
appl_menu();
}
void clickattn(short itm, cnr *cp)
{
static unsigned char spctab[8] =
{171, 170, 167, 168, 181, 183, 184, 189};
unsigned char code;
if ((itm < 1) | (itm > 32)) return;
if (itm > 24) {
code = spctab[itm-25];
}
else code = itm + 142;
if (cp->serflg) serin(code, 0, cp);
else if (cp->tcpflg) tcpin(0, code, 0, cp);
else sain(0, code, 0, cp);
}
void appl_menu(void) /* enable correct application menus */
{
static char last_da = 2; /* init to invalid value */
static char last_frontcp = 2;
static char last_fkey = 2;
static char last_conns = 2;
static char last_tcp = 2;
char new_da, new_frontcp, new_fkey, new_conns, new_tcp;
cnr *cp;
short i;
/* skip drawing menu if no changes from last time */
new_da = da_menu;
cp = front_cp();
if (cp == 0) {
new_frontcp = new_fkey = 0;
}
else {
new_frontcp = 1;
new_fkey = cp->showfkey;
}
new_conns = 0;
for (i=0; i < MAXSESSIONS; i ++) {
if (cplist[i] != 0) {
new_conns = 1;
break;
}
}
new_tcp = havetcp;
if ((last_da == new_da) &&
(last_frontcp == new_frontcp) &&
(last_fkey == new_fkey) &&
(last_conns == new_conns) &&
(last_tcp == new_tcp)) return;
last_da = new_da; /* save values for next time */
last_frontcp = new_frontcp;
last_fkey = new_fkey;
last_conns = new_conns;
last_tcp = new_tcp;
if (new_da) {
DisableItem(myMenus[3], 0);
DisableItem(myMenus[4], 0);
DisableItem(myMenus[5], 0);
DisableItem(myMenus[6], 0);
}
else {
enable_menu_item(myMenus[3], 0, new_frontcp);
enable_menu_item(myMenus[4], 0, new_fkey);
enable_menu_item(myMenus[5], 0, new_tcp);
enable_menu_item(myMenus[6], 0, new_conns);
}
DrawMenuBar();
}
void enable_menu_item(MenuHandle theMenu,
short item,
char enableflag)
{
if (enableflag) {
EnableItem(theMenu, item);
}
else {
DisableItem(theMenu, item);
}
}
void new_connmenu(void)
{
cnr *cp;
short i, j, m_index, menusize;
unsigned char newname[256];
m_index = 1;
for (i=0; i < MAXSESSIONS; i++) {
cp = cplist[i];
if (cp != 0) menu_cplist[m_index++] = cp;
}
menusize = m_index-1;
while (m_index < MAXSESSIONS+1) {
menu_cplist[m_index++] = 0;
}
DeleteMenu(connMenu);
ReleaseResource((Handle)myMenus[6]);
myMenus[6] = GetMenu(connMenu);
InsertMenu(myMenus[6], connMenu);
if (menusize == 0) return;
if (menusize > 1) { /* sort items in array */
menu_cplist[0] = 0;
for (i=2; i <= menusize; i++) {
cp = menu_cplist[i];
j = i;
while (sessnamecomp(menu_cplist[j-1], cp)) {
menu_cplist[j] = menu_cplist[j-1];
j = j-1;
}
menu_cplist[j] = cp;
}
}
for (i = 1; i <= menusize; i++) {
cp = menu_cplist[i];
get_sessname(newname, cp);
c2pstr(newname);
AppendMenu(myMenus[6], newname);
}
}
Boolean sessnamecomp(cnr *a, cnr *b)
{
char result;
if (a == 0) return(false);
result = strcmp(a->sessname, b->sessname);
if (result < 0) return(false);
if (result > 0) return(true);
return((a->sessnameseq) > (b->sessnameseq));
}